home *** CD-ROM | disk | FTP | other *** search
Wrap
class TakGround extends SideScroller.MovingObject { var bReactToCollisions; var bGoingLeft; var bGoingRight; var nMSLostTimer; var bCrouched; var bEasterEgg; var aEEObj; var bReachedEnd; var nSmokeDelay; var oKeysManager; var oBoarSound; var oBoarStepSound; var bPepperReaction; var nPepperColor; var bPepperColorActive; var mcRef; var oStunnedSound; var oPepperLoopSound; var oPepperStartSound; var bNeedToCrouch; var oLayer; var nSpeedX; var nPepperTimer; var nStunnedTime; var sState; var bShouldMove; static var oCtrl; static var BOAR_SOUNDS = ["Boar_Sound_01.mp3","Boar_Sound_02.mp3","Boar_Sound_03.mp3","Boar_Sound_04.mp3","Boar_Sound_05.mp3","Boar_Sound_06.mp3","Boar_Sound_07.mp3","Boar_Sound_08.mp3","Boar_Sound_09.mp3","Boar_Sound_10.mp3","Boar_Sound_11.mp3"]; static var BOAR_STEP_SOUNDS = ["Boar_Step_01.mp3","Boar_Step_02.mp3","Boar_Step_03.mp3","Boar_Step_04.mp3","Boar_Step_05.mp3","Boar_Step_06.mp3","Boar_Step_07.mp3","Boar_Step_08.mp3","Boar_Step_09.mp3"]; static var SMOKE_DELAY = 3; static var SMOKE_RANDOM = 3; static var CROUCH_SPEED = 8; static var CRUISE_CONTROL_SPEED = 9; static var SLOW_DOWN_SPEED = 4; static var RUN_SPEED = 14; static var SPEED_CHANGE = 1.2; static var MIN_SPEED_AIR = 4; static var MAX_SPEED_AIR = 11; static var MOY_SPEED_AIR = 8; static var ACCELERATION_AIR = 0.25; static var DIRECTION_CHANGE_FACTOR_AIR = 0.85; static var JUMPSPEED = 14; static var STUNNED_TIME = 22; static var EASTER_EGG_KEY = "E"; static var BOAR_SOUND_KEY = "B"; static var CAMERA_GAP_SPEED_CHANGE = 1.5; static var CAMERA_GAP_SPEED_CHANGE_FAST = 3.5; static var nPEPPER_REACTION_TIME = 90; static var nPEPPER_FLASH_INTERVAL = 3; static var nINVINCINBLE_SPEED_MOD = 1.5; static var nMINIMUM_DELAY_MS_LOST = 90; function TakGround(__mcRef, __oLayer) { super(__mcRef,__oLayer); TakGround.oCtrl = this; this.bReactToCollisions = !Main.Instance.CodeBoxManager.Invincible; this.bGoingLeft = false; this.bGoingRight = false; this.nMSLostTimer = 0; this.bCrouched = false; this.bEasterEgg = false; this.aEEObj = new Array(); this.bReachedEnd = false; this.nSmokeDelay = TakGround.SMOKE_DELAY; this.oKeysManager = new Library.Utils.KeysManager(); this.oKeysManager.setListenerForKey(this,String(TakGround.EASTER_EGG_KEY).charCodeAt(0)); this.oKeysManager.setListenerForKey(this,String(TakGround.BOAR_SOUND_KEY).charCodeAt(0)); this.oKeysManager.setListenerForKey(this,38); this.oKeysManager.setListenerForKey(this,40); this.oKeysManager.setListenerForKey(this,37); this.oKeysManager.setListenerForKey(this,39); this.oKeysManager.setListenerForKey(this,32); this.setState("CruiseControl"); } static function get Instance() { return TakGround.oCtrl; } function doBoarSound() { if(Library.Sound.SoundManager.SoundsQty <= 6) { var _loc2_ = Library.Utils.MoreMath.getRandomRange(0,TakGround.BOAR_SOUNDS.length - 1); var _loc3_ = TakGround.BOAR_SOUNDS[_loc2_]; this.oBoarSound.doStop(); this.oBoarSound = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,_loc3_,180,1); } } function doBoarStepSound() { if(Library.Sound.SoundManager.SoundsQty <= 6) { var _loc2_ = Library.Utils.MoreMath.getRandomRange(0,TakGround.BOAR_STEP_SOUNDS.length - 1); var _loc3_ = TakGround.BOAR_STEP_SOUNDS[_loc2_]; this.oBoarStepSound.doStop(); this.oBoarStepSound = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,_loc3_); } } function doEnterFrame() { super.doEnterFrame(); this.nMSLostTimer = this.nMSLostTimer - 1; if(this.bPepperReaction) { this.nPepperColor = this.nPepperColor - 1; if(this.nPepperColor <= 0) { this.bPepperColorActive = !this.bPepperColorActive; this.nPepperColor = TakGround.nPEPPER_FLASH_INTERVAL; if(this.bPepperColorActive) { var _loc4_ = [1.68562018483454,0.129222856217665,-1.06484304105221,0,-29.125,-0.506833163112779,1.05012620416499,0.206706958947793,0,-29.125,0.46966683688722,-1.37227714378233,1.65261030689511,0,-29.125,0,0,0,1,0]; var _loc5_ = new flash.filters.ColorMatrixFilter(_loc4_); this.mcRef.filters = [_loc5_]; } else { this.mcRef.filters = []; } } } for(var _loc3_ in this.aEEObj) { if(this.aEEObj[_loc3_]._currentframe == undefined) { this.aEEObj.splice(Number(_loc3_),1); } } } function doPause() { super.doPause(); this.oStunnedSound.doPause(); this.oPepperLoopSound.doPause(); this.oPepperStartSound.doPause(); for(var _loc4_ in this.aEEObj) { for(var _loc3_ in this.aEEObj[_loc4_]) { this.aEEObj[_loc4_][_loc3_].stop(); } } } function doResume() { super.doResume(); this.oStunnedSound.doResume(); this.oPepperLoopSound.doResume(); this.oPepperStartSound.doResume(); for(var _loc4_ in this.aEEObj) { for(var _loc3_ in this.aEEObj[_loc4_]) { this.aEEObj[_loc4_][_loc3_].play(); } } if(this.mcRef.mcHeadSwing.mcAnim._currentframe == 1) { this.mcRef.mcHeadSwing.mcAnim.stop(); } var _loc5_ = true; if(this.CurrentState.indexOf("Stunned") != -1) { _loc5_ = false; } else if(this.CurrentState.indexOf("Feather") != -1) { _loc5_ = false; } else if(this.CurrentState.indexOf("Jump") != -1) { _loc5_ = false; } this.bGoingLeft = this.oKeysManager.isKeyDown(37); this.bGoingRight = this.oKeysManager.isKeyDown(39); this.bNeedToCrouch = this.oKeysManager.isKeyDown(40); this.bCrouched = this.bNeedToCrouch; if(_loc5_) { this.doUnlockState(); if(!this.bCrouched) { if(!this.bPepperReaction) { if(this.bGoingLeft) { this.setState("SlowDown"); } else if(this.bGoingRight) { this.setState("Run"); } else { this.setState("CruiseControl"); } } else { this.setState("Run"); } } else { this.setState("CrouchRun"); } } } function doSoundEvent(__nEvent, __oSound) { if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE) { if(__oSound == this.oStunnedSound) { delete this.oStunnedSound; } if(__oSound == this.oPepperLoopSound) { delete this.oPepperLoopSound; } if(__oSound == this.oPepperStartSound) { delete this.oPepperStartSound; this.oPepperLoopSound = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"PimentActive.wav",100,9999); } } } function onKeyManagerEvent(__nEvent, __nCode) { if(!this.Paused) { switch(__nEvent) { case Library.Utils.KeysManager.EVENT_KEY_DOWN: switch(__nCode) { case String(TakGround.EASTER_EGG_KEY).charCodeAt(0): this.onToggleEE(); break; case String(TakGround.BOAR_SOUND_KEY).charCodeAt(0): this.doBoarSound(); break; case 37: this.bGoingLeft = true; if(!this.bPepperReaction) { if(!this.bCrouched) { this.setState("SlowDown"); } else { this.setState("CrouchRun"); } } break; case 39: this.bGoingRight = true; if(!this.bPepperReaction) { if(!this.bCrouched) { this.setState("Run"); } else { this.setState("CrouchRun"); } } break; case 40: this.setState("CrouchRun"); this.bNeedToCrouch = true; break; case 38: if(!this.bCrouched) { this.setState("JumpStart"); } break; case 32: if(this.mcRef.mcHeadSwing != undefined) { if(this.mcRef.mcHeadSwing.mcAnim._currentframe == 1) { this.mcRef.mcHeadSwing.mcAnim.play(); var _loc3_ = Library.Utils.MoreMath.getRandomRange(1,3); var _loc2_ = "new_boar_head_swing-0" + _loc3_ + ".mp3"; Library.Sound.SoundManager.isSoundPlaying("new_boar_head_swing-01.mp3").oSound.doStop(); Library.Sound.SoundManager.isSoundPlaying("new_boar_head_swing-02.mp3").oSound.doStop(); Library.Sound.SoundManager.isSoundPlaying("new_boar_head_swing-03.mp3").oSound.doStop(); Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,_loc2_); } } } break; case Library.Utils.KeysManager.EVENT_KEY_UP: switch(__nCode) { case 37: this.bGoingLeft = false; if(!this.bPepperReaction) { if(this.bGoingRight) { if(!this.bCrouched) { this.setState("Run"); } else { this.setState("CrouchRun"); } } else if(!this.bCrouched) { this.setState("CruiseControl"); } else { this.setState("CrouchRun"); } } break; case 39: this.bGoingRight = false; if(!this.bPepperReaction) { if(this.bGoingLeft) { if(!this.bCrouched) { this.setState("SlowDown"); } else { this.setState("CrouchRun"); } } else if(!this.bCrouched) { this.setState("CruiseControl"); } else { this.setState("CrouchRun"); } } break; case 40: if(!this.bPepperReaction) { if(this.bGoingLeft) { this.setState("SlowDown"); } else if(this.bGoingRight) { this.setState("Run"); } else { this.setState("CruiseControl"); } } else { this.setState("Run"); } this.bNeedToCrouch = false; } } } } function onHitSpecial(__oRef) { if(__oRef instanceof MiniStone) { Game.Instance.onCatchMiniStone(); } else if(__oRef instanceof MoonStone) { Game.Instance.onCatchMoonstone(); } else if(__oRef instanceof Feather) { this.doForcedSetState("FeatherCatch"); this.doLockState(); } else if(__oRef instanceof Pepper) { this.doPepperReaction(); } else if(__oRef instanceof EndTrigger) { if(!this.bReachedEnd) { LevelManager.Instance.onTakReachEnd(); this.bReachedEnd = true; } } } function onBackFromMiniGame() { this.doForcedSetState("FeatherBackOnEarth"); } function doReactCollision() { if(!Main.Instance.CodeBoxManager.Invincible) { this.doForcedSetState("StunnedStart"); this.doLockState(); if(Game.Instance.MSQty > 0 && this.nMSLostTimer <= 0) { var _loc3_ = this.oLayer.doAttachVisual("mcMoonStoneLost"); _loc3_._x = this.mcRef._x; _loc3_._y = this.mcRef._y; var _loc4_ = new MSLost(_loc3_,this.oLayer); this.nMSLostTimer = TakGround.nMINIMUM_DELAY_MS_LOST; Game.Instance.onLostMoonstone(); } super.doReactCollision(); } else { Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"ItemHit.mp3"); } } function doSetEEOn(__mc) { if(!Library.Utils.Tools.isItemInArray(this.aEEObj,__mc)) { this.aEEObj.push(__mc); } __mc.gotoAndStop(this.EeLabel); } function doDestroy() { delete this.oBoarSound; delete this.oBoarStepSound; delete this.aEEObj; this.oKeysManager.doDestroy(); delete this.oKeysManager; this.oStunnedSound.doDestroy(); delete this.oStunnedSound; delete TakGround.oCtrl; super.doDestroy(); } function get EeLabel() { var _loc2_ = "Male"; if(this.bEasterEgg) { _loc2_ = "Female"; } return _loc2_; } function get IsInHeadSwing() { var _loc2_ = undefined; if(this.mcRef.mcHeadSwing.mcAnim._currentframe == undefined) { _loc2_ = false; } else { _loc2_ = this.mcRef.mcHeadSwing.mcAnim._currentframe != 1; } return _loc2_; } function doFeatherBackOnEarth() { if(this.isStateComplete()) { this.doUnlockState(); this.bCrouched = false; if(!this.bPepperReaction) { this.setState("CruiseControl"); } else { this.setState("Run"); } } this.doNormalizeCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE); this.nSpeedX = 0; } function doFeatherNoTak() { this.doSetSpeeds(undefined,-1,true); } function doFeatherCatch() { this.mcRef._rotation = 0; if(this.isStateComplete()) { this.doForcedSetState("FeatherNoTak"); Game.Instance.onFeatherCatch(); } this.doSetSpeeds(undefined,-1,true); this.doNormalizeCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE); } function doJumpLoop() { this.doJumpMove(); } function doJumpStart() { if(this.isStateComplete()) { this.doForcedSetState("JumpLoop"); } this.doJumpMove(); } function doCrouchRun() { var _loc2_ = undefined; if(this.bPepperReaction) { _loc2_ = TakGround.RUN_SPEED; } else { _loc2_ = TakGround.CROUCH_SPEED; } if(Main.Instance.CodeBoxManager.Invincible) { _loc2_ *= TakGround.nINVINCINBLE_SPEED_MOD; } this.nSpeedX = Library.Utils.MoreMath.getReachNum(this.nSpeedX,_loc2_,TakGround.SPEED_CHANGE); this.doAddSmoke(); this.doNormalizeCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE); } function doCruiseControl() { var _loc2_ = TakGround.CRUISE_CONTROL_SPEED; if(Main.Instance.CodeBoxManager.Invincible) { _loc2_ *= TakGround.nINVINCINBLE_SPEED_MOD; } this.nSpeedX = Library.Utils.MoreMath.getReachNum(this.nSpeedX,_loc2_,TakGround.SPEED_CHANGE); this.doAddSmoke(); this.doNormalizeCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE); } function doRun() { if(this.bPepperReaction) { this.nPepperTimer = this.nPepperTimer - 1; if(this.nPepperTimer <= 0) { this.bPepperReaction = false; this.mcRef.filters = []; this.oPepperLoopSound.doFadeTo(0); if(!this.bGoingRight) { if(this.bGoingLeft) { this.setState("SlowDown"); } else { this.setState("CruiseControl"); } } } } var _loc2_ = TakGround.RUN_SPEED; if(Main.Instance.CodeBoxManager.Invincible) { _loc2_ *= TakGround.nINVINCINBLE_SPEED_MOD; } this.nSpeedX = Library.Utils.MoreMath.getReachNum(this.nSpeedX,_loc2_,TakGround.SPEED_CHANGE); this.doAddSmoke(); this.doEnlargeCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE_FAST); } function doSlowDown() { this.nSpeedX = Library.Utils.MoreMath.getReachNum(this.nSpeedX,TakGround.SLOW_DOWN_SPEED,TakGround.SPEED_CHANGE); this.doAddSmoke(); this.doReduceCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE_FAST); } function doStunnedEnd() { if(this.isStateComplete()) { this.doUnlockState(); if(!this.bNeedToCrouch) { if(!this.bPepperReaction) { if(this.bGoingLeft) { this.setState("SlowDown"); } else if(this.bGoingRight) { this.setState("Run"); } else { this.setState("CruiseControl"); } } else { this.setState("Run"); } } else { this.setState("CrouchRun"); } } this.doNormalizeCameraGap(3); } function doStunnedStart() { if(this.isStateComplete()) { this.nStunnedTime = TakGround.STUNNED_TIME; this.doForcedSetState("StunnedLoop"); } this.doNormalizeCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE); } function doStunnedLoop() { this.nSpeedX = Library.Utils.MoreMath.getReachZero(this.nSpeedX,2.5); if(this.nStunnedTime > 0) { this.nStunnedTime = this.nStunnedTime - 1; } else { this.doForcedSetState("StunnedEnd"); } this.doNormalizeCameraGap(TakGround.CAMERA_GAP_SPEED_CHANGE); } function doPepperReaction() { this.nPepperTimer = TakGround.nPEPPER_REACTION_TIME; this.bPepperReaction = true; if(!this.bCrouched) { this.setState("Run"); } else { this.setState("CrouchRun"); } this.oPepperStartSound.doStop(); delete this.oPepperStartSound; this.oPepperLoopSound.doStop(); delete this.oPepperLoopSound; this.oPepperStartSound = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"CatchPiment.mp3"); this.oPepperStartSound.doAddListener(this); this.bPepperColorActive = false; this.nPepperColor = TakGround.nPEPPER_FLASH_INTERVAL; } function onToggleEE() { this.bEasterEgg = !this.bEasterEgg; for(var _loc2_ in this.aEEObj) { this.aEEObj[_loc2_].gotoAndStop(this.EeLabel); } this.doBoarSound(); } function doNormalizeCameraGap(__nChange) { if(SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX > 0) { SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX = SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX - __nChange; if(SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX < 0) { SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX = 0; } } else if(SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX < 0) { SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX = SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX + __nChange; if(SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX > 0) { SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX = 0; } } } function doReduceCameraGap(__nChange) { if(SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX > -100) { SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX = SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX - __nChange; } } function doEnlargeCameraGap(__nChange) { if(SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX < 175) { SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX = SideScroller.SideScrollerManager.Instance.CameraManager.FollowAddonX + __nChange; } } function doAddSmoke() { if(this.nSmokeDelay == 0) { this.nSmokeDelay = TakGround.SMOKE_DELAY; var _loc3_ = undefined; if(Main.Instance.CodeBoxManager.Invincible) { _loc3_ = "Dynamic_TrailStar"; } else { _loc3_ = "Dynamic_TrailSmoke"; } var _loc2_ = this.ParentLayer.doAttachVisual(_loc3_); _loc2_._x = this.Ref._x + Library.Utils.MoreMath.getRandomRange(- TakGround.SMOKE_RANDOM,TakGround.SMOKE_RANDOM); _loc2_._y = this.Ref._y + Library.Utils.MoreMath.getRandomRange(- TakGround.SMOKE_RANDOM,TakGround.SMOKE_RANDOM); var _loc4_ = new TrailSmoke(_loc2_,this.ParentLayer); } else { this.nSmokeDelay = this.nSmokeDelay - 1; } } function doJumpMove() { if(this.bGoingRight || this.bPepperReaction) { if(this.nSpeedX < 0) { this.nSpeedX *= TakGround.DIRECTION_CHANGE_FACTOR_AIR; } var _loc2_ = TakGround.MAX_SPEED_AIR; if(Main.Instance.CodeBoxManager.Invincible) { _loc2_ *= TakGround.nINVINCINBLE_SPEED_MOD; } if(this.nSpeedX < _loc2_) { this.doSetSpeeds(TakGround.ACCELERATION_AIR,undefined,true); } else { this.nSpeedX = TakGround.MAX_SPEED_AIR; } } else if(this.bGoingLeft) { if(this.nSpeedX > 0) { this.nSpeedX *= TakGround.DIRECTION_CHANGE_FACTOR_AIR; } if(this.nSpeedX > TakGround.MIN_SPEED_AIR) { this.doSetSpeeds(- TakGround.ACCELERATION_AIR,undefined,true); } else { this.nSpeedX = TakGround.MIN_SPEED_AIR; } } else { this.nSpeedX = Library.Utils.MoreMath.getReachNum(this.nSpeedX,TakGround.MOY_SPEED_AIR,TakGround.ACCELERATION_AIR); } if(Main.Instance.CodeBoxManager.Invincible) { this.doAddSmoke(); } } function onHitGround() { if(this.CurrentState == "JumpStart" || this.CurrentState == "JumpLoop") { this.doUnlockState(); this.nSmokeDelay = 0; if(!this.bNeedToCrouch) { if(!this.bPepperReaction) { if(this.bGoingLeft) { this.setState("SlowDown"); } else if(this.bGoingRight) { this.setState("Run"); } else { this.setState("CruiseControl"); } } else { this.setState("Run"); } } else { this.setState("CrouchRun"); } this.doBoarSound(); } } function doLoadStateAction() { super.doLoadStateAction(); switch(this.sState) { case "FeatherCatch": Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Feather.mp3"); Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Feather_Go.mp3"); break; case "StunnedStart": Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Hurt.mp3",100,1,true); this.bShouldMove = false; break; case "StunnedLoop": this.oStunnedSound.doStop(); this.oStunnedSound.doDestroy(); delete this.oStunnedSound; this.oStunnedSound = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Stunned.mp3",100,999,true); this.oStunnedSound.doAddListener(this); break; case "StunnedEnd": this.oStunnedSound.setFadeRate(15); this.oStunnedSound.doFadeTo(0); this.bShouldMove = true; break; case "CrouchRun": this.bCrouched = true; this.doBoarSound(); break; case "JumpStart": this.doLockState(); this.doBoarSound(); this.doSetSpeeds(undefined,- TakGround.JUMPSPEED,true); Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Jump.mp3"); } } function doUnLoadStateAction() { super.doUnLoadStateAction(); switch(this.sState) { case "CrouchIdle": case "CrouchRun": this.bCrouched = false; } } }